﻿using Sys.Workflow.Bpmn.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sys.Workflow.Engine.impl
{
    /* Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     *      http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */


    /**
     * Helper for changing the state of a process instance.
     *
     * An instance can be obtained through {@link org.flowable.engine.RuntimeService#createChangeActivityStateBuilder()}.
     *
     * @author Tijs Rademakers
     */
    public interface ChangeActivityStateBuilder
    {

        /**
         * Set the id of the process instance
         **/
        ChangeActivityStateBuilder SetProcessInstanceId(string processInstanceId);

        /**
         * Set the id of the execution for which the activity should be changed
         **/
        ChangeActivityStateBuilder MoveExecutionToActivityId(string executionId, string activityId);

        /**
         * Set the ids of the executions which should be changed to a single execution with the provided activity id.
         * This can be used for parallel execution like parallel/inclusive gateways, multiinstance, event sub processes etc.
         **/
        ChangeActivityStateBuilder MoveExecutionsToSingleActivityId(List<string> executionIds, string activityId);

        /**
         * Set the id of an execution which should be changed to multiple executions with the provided activity ids.
         * This can be used for parallel execution like parallel/inclusive gateways, multiinstance, event sub processes etc.
         **/
        ChangeActivityStateBuilder MoveSingleExecutionToActivityIds(string executionId, List<string> activityId);

        /**
         * Moves the execution with the current activity id to the provided new activity id
         */
        ChangeActivityStateBuilder MoveActivityIdTo(string currentActivityId, string newActivityId);
        ChangeActivityStateBuilder MoveActivityIdTo(string currentActivityId, string newActivityId, string? newAssigneeId, string? newOwnerId);
        /**
         * Set the activity ids that should be changed to a single activity id.
         * This can be used for parallel execution like parallel/inclusive gateways, multiinstance, event sub processes etc.
         */
        ChangeActivityStateBuilder MoveActivityIdsToSingleActivityId(List<string> currentActivityIds, string newActivityId);

        /**
         * Set the activity id that should be changed to multiple activity ids.
         * This can be used for parallel execution like parallel/inclusive gateways, multiinstance, event sub processes etc.
         */
        ChangeActivityStateBuilder MoveSingleActivityIdToActivityIds(string currentActivityId, List<string> newActivityIds);

        /**
         * Moves the execution with the current activity id to an activity id in the parent process instance.
         * The sub process instance will be terminated, so all sub process instance executions need to be moved.
         */
        ChangeActivityStateBuilder MoveActivityIdToParentActivityId(string currentActivityId, string newActivityId);

        /**
         * Moves the execution with the current activity id to an activity id in a new sub process instance for the provided call activity id.
         */
        ChangeActivityStateBuilder MoveActivityIdToSubProcessInstanceActivityId(string currentActivityId, string newActivityId, String callActivityId);

        /**
         * Moves the execution with the current activity id to an activity id in a new sub process instance of the specific definition version for the provided call activity id.
         */
        ChangeActivityStateBuilder MoveActivityIdToSubProcessInstanceActivityId(string currentActivityId, string newActivityId, string callActivityId, long subProcessDefinitionVersion);

        /**
         * Enables a new start event in an event sub process.
         */
        ChangeActivityStateBuilder EnableEventSubProcessStartEvent(string eventSubProcessStartEventId);

        /**
         * Sets a process scope variable
         */
        ChangeActivityStateBuilder ProcessVariable(string processVariableName, object processVariableValue);

        /**
         * Sets multiple process scope variables
         */
        ChangeActivityStateBuilder ProcessVariables(Dictionary<string, object> processVariables);

        /**
         * Sets a local scope variable for a start activity id
         */
        ChangeActivityStateBuilder LocalVariable(string startActivityId, string localVariableName, object localVariableValue);

        /**
         * Sets multiple local scope variables for a start activity id
         */
        ChangeActivityStateBuilder LocalVariables(string startActivityId, Dictionary<string, object> localVariables);

        /**
         * Start the process instance
         *
         * @throws FlowableObjectNotFoundException
         *             when no process instance is found
         * @throws FlowableException
         *             activity could not be canceled or started
         **/
        void ChangeState();
    }
}
